﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MakeItWeb.Framework
{
    public struct AdminMenu
    {
        public string Text { get; set; }
        public string NavigationUrl { get; set; }
        public string IconImageUrl { get; set; }
    }

    public class MakeItWebMasterPage : System.Web.UI.MasterPage, IMakeItWebControl
    {
        private List<AdminMenu> _AdminMenuItems = new List<AdminMenu>();

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!(Page is MakeItWebPage))
                throw new ApplicationException("The Page must be derived from MakeItWebPage.");
        }

        protected IEnumerable<AdminMenu> AdminMenuItems
        {
            get { return _AdminMenuItems.ToArray(); }
        }

        #region IMakeItWebControl members

        public HtmlPage CurrentHtmlPage
        {
            get { return (Page as IMakeItWebControl).CurrentHtmlPage; }
        }

        public string CurrentUserName
        {
            get { return (Page as IMakeItWebControl).CurrentUserName; }
        }

        public Member CurrentMember
        {
            get { return (Page as IMakeItWebControl).CurrentMember; }
        }

        public bool WebOnlyMemberInd
        {
            get { return (Page as IMakeItWebControl).WebOnlyMemberInd; }
        }

        public bool DisplayMemberSearchInd
        {
            get
            {
                return (Page as IMakeItWebControl).DisplayMemberSearchInd;
            }
            set
            {
                (Page as IMakeItWebControl).DisplayMemberSearchInd = value;
            }
        }

        public bool DisplayDynamicBackgroundForAdmin
        {
            get { return (Page as IMakeItWebControl).DisplayDynamicBackgroundForAdmin; }
        }

        public bool IsInRole(string sRoleName)
        {
            return (Page as IMakeItWebControl).IsInRole(sRoleName);
        }

        public bool IsPageAdministrator()
        {
            return (Page as IMakeItWebControl).IsPageAdministrator();
        }

        public virtual void RegisterAdminFunction(string sText, string sNavigationUrl, string sIconImageUrl)
        {
            _AdminMenuItems.Add(new AdminMenu() { Text = sText, NavigationUrl = sNavigationUrl, IconImageUrl = sIconImageUrl });
        }

        public virtual void ClearAdminFunctions()
        {
            _AdminMenuItems.Clear();
        }

        public string SelectedSection
        {
            get { return (Page as IMakeItWebControl).SelectedSection; }
        }
        #endregion
    }
}